//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package miiteen.demo.web.controller;

import io.swagger.annotations.ApiOperation;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import miiteen.common.json.JsonUtil;
import miiteen.common.utils.JacksonMapper;
import miiteen.core.result.ResultMessage;
import miiteen.core.result.ResultMessageTool;
import miiteen.data.beans.PageBounds;
import miiteen.demo.web.beans.CommentInfo;
import miiteen.demo.web.service.CommentInfoService;
import miiteen.sys.base.controller.BaseAction;
import net.sf.json.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/demo/web/commentinfo")
@CrossOrigin
public class CommentInfoController extends BaseAction {
    @Autowired
    private CommentInfoService commentInfoService;

    @ApiOperation("保存批示")
    @RequestMapping(
        value = {"/save"},
        method = {RequestMethod.POST}
    )
    @ResponseBody
    public ResultMessage<Object> save(@RequestBody CommentInfo commentInfo) {
        long result = this.commentInfoService.save(commentInfo);
        return result > 0L ? ResultMessageTool.Success("保存成功") : ResultMessageTool.Error("保存失败");
    }


    @ApiOperation("删除批示")
    @RequestMapping("/deleteComment")
    @ResponseBody
    public ResultMessage<Object> delete(@RequestParam String id) {
        long result = commentInfoService.deleteSingle(id);
        if (result > 0) {
            return ResultMessageTool.Success("删除成功");
        } else {
            return ResultMessageTool.Error("删除失败");
        }
    }


    @ApiOperation("保存批示")
    @RequestMapping({"/saveTest"})
    @ResponseBody
    public ResultMessage<Object> saveTest(@RequestParam String baseInfoId) {
        CommentInfo commentInfo=new CommentInfo();
        commentInfo.setBaseInfoId(baseInfoId);
        commentInfo.setMediaTypeId("3e1afcd9-f106-492e-b3b5-13f1a2d4df36");
        commentInfo.setCommentJobNo("1111");
        commentInfo.setCommentPersonName("测试");
        commentInfo.setCommentPosition("测试职位");
        commentInfo.setCommentContent("测试批示内容");
        commentInfo.setCommentTime(new Date());
        commentInfo.setCreateTime(new Date());
        commentInfo.setUpdateTime(null);
        commentInfo.setDelState(0);
        commentInfo.setYlzd1(null);
        commentInfo.setYlzd2(0);
        long result = this.commentInfoService.save(commentInfo);
        return result > 0L ? ResultMessageTool.Success("保存成功") : ResultMessageTool.Error("保存失败");
    }




    @RequiresPermissions("commentInfo:list")
    @RequestMapping(value = "/list")
    public ModelAndView list() {
        //设置列表关联JSP页面
        ModelAndView mv = new ModelAndView("demo/web/commentInfoList");
        //自行设置默认查询条件

        return mv;
    }

    @RequiresPermissions("commentInfo:list")
    @RequestMapping("/search")
    @ResponseBody
    public String search(@RequestBody JSONObject jsonObject) {
        //获取查询条件
        PageBounds pageBounds = JsonUtil.jsonobjToObj(jsonObject.getJSONObject("pagecon"), PageBounds.class);
        Map<String, Object> map = JsonUtil.jsonobjToMap(jsonObject.getJSONObject("searchcon"));


        List<CommentInfo> list = commentInfoService.findListByMap(map, pageBounds);
        if (list != null && list.size() > 0) {
            return JacksonMapper.getListToJson(ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list));
        } else {
            return JacksonMapper.getListToJson(ResultMessageTool.Error(""));
        }
    }

    @RequiresPermissions("commentInfo:edit")
    @RequestMapping(value = "/edit")
    public ModelAndView edit(@ModelAttribute("noticeInfo") CommentInfo commentInfo) {
        ModelAndView mv = new ModelAndView("demo/web/commentInfoEdit");
        Map<String,Object> map=new HashMap<>();
        if (commentInfo.getId() > 0) {
            CommentInfo bean = commentInfoService.findById(commentInfo.getId());
            commentInfo = bean;
        }

        //返回对象JSON字符串
        mv.addObject("noticeInfo", JsonUtil.toJsonStr(commentInfo));
        return mv;
    }




    @RequiresPermissions("commentInfo:del")
    @RequestMapping(value = "/del")
    @ResponseBody
    public String del(@RequestParam String ids) {
        ResultMessage resultMessage = new ResultMessage();
        if (!ids.equals("")) {
            int result = commentInfoService.delete(ids);
            if (result > 0) {
                resultMessage = ResultMessageTool.Success("删除成功");
            } else {
                resultMessage = ResultMessageTool.Error("删除失败");
            }
        } else {
            resultMessage = ResultMessageTool.Error("请选择要删除的数据");
        }
        return JsonUtil.toJsonStr(resultMessage);
    }

}
